import hover from '../../ProcessManagement/designer/components/hover';
import { ProcessMonitoring as locale } from './locale';
import {
  createInbizSchema,
  createComponentStyleSchema,
  createDecoratorStyleSchema,
} from '@inbiz/setters';
import ProcessGroupSelector from './components/ProcessGroupSelector';

export const defaultProps = {
  queryRegion: true,
  GetPage: '20',
  queryCondition: [
    '流程编号',
    '发起人',
    '流程名称',
    '流程分组',
    '流程状态',
    '发起时间',
    '完成时间',
  ],
  ToolbarOperation: ['查看当前审核人'],
  InlineOperation: ['流程日志', '变量', '流程详情', '终止', '删除'],
  processGroup: true,
  ScopeProcess: ['all'],
};

export const Schema = createInbizSchema({
  attribute: {
    base: {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-display': {
          type: 'string',
          enum: ['visible', 'hidden'],
          'x-decorator': 'FormItem',
          'x-component': 'Select',
          'x-component-props': {
            defaultValue: 'visible',
          },
        },
        'x-component-props': {
          type: 'object',
          properties: {
            //分页数
            GetPage: {
              type: 'array',
              'x-decorator': 'FormItem',
              'x-component': 'Select',
              enum: ['10', '20', '30', '50', '100'],
            },
            //查询区域
            queryRegion: {
              type: 'boolean',
              'x-decorator': 'FormItem',
              'x-component': 'Switch',
              'x-component-props': {},
            },
            //查询条件
            queryCondition: {
              type: 'array',
              'x-decorator': 'FormItem',
              'x-component': 'Checkbox.Group',
              'x-reactions': {
                dependencies: ['.queryRegion'],
                when: '{{$deps[0]==true}}',
                fulfill: {
                  state: {
                    visible: true,
                    value: [
                      '流程编号',
                      '发起人',
                      '流程名称',
                      '流程分组',
                      '流程状态',
                      '发起时间',
                      '完成时间',
                    ],
                  },
                },
                otherwise: {
                  state: {
                    visible: false,
                  },
                },
              },
              enum: [
                '流程编号',
                '发起人',
                '流程名称',
                '流程分组',
                '流程状态',
                '发起时间',
                '完成时间',
              ],
            },
            //工具栏操作
            ToolbarOperation: {
              type: 'array',
              'x-decorator': 'FormItem',
              'x-component': 'Checkbox.Group',
              enum: ['查看当前审核人'],
            },
            // 行内操作
            InlineOperation: {
              type: 'array',
              'x-decorator': 'FormItem',
              'x-component': 'Checkbox.Group',
              enum: ['流程日志', '变量', '流程详情', '终止', '删除'],
            },
            //流程分组
            processGroup: {
              type: 'boolean',
              'x-decorator': 'FormItem',
              'x-component': 'Switch',
              'x-component-props': {
                defaultChecked: true,
              },
            },
            //流程范围
            ScopeProcess: {
              type: 'array',
              'x-decorator': 'FormItem',
              'x-component': 'Select',
              enum: ['all', 'currentApplication', 'group'],
            },
            processGroupSelector: {
              type: 'string',
              'x-decorator': 'FormItem',
              'x-component': ProcessGroupSelector,
              'x-reactions': {
                dependencies: ['.ScopeProcess'],
                when: "{{$deps[0] == 'group'}}",
                fulfill: {
                  state: {
                    visible: true,
                  },
                },
                otherwise: {
                  state: {
                    visible: false,
                  },
                },
              },
            },
            exposureConfig: {
              type: 'object',
              'x-component': 'CollapseItem',
              properties: {
                ownership: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': hover,
                  'x-component-props': {
                    tooltip: '流程扩展业务,开启后新增流程来源列',
                    label: 'ProcessMonitoring.ownership',
                  },
                },
              },
            },
          },
        },
      },
    },
  },
  style: {
    ...createComponentStyleSchema(),
    ...createDecoratorStyleSchema(),
  },
});

export const defaultResource = {
  icon: 'ProcessMonitoring',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'string',
        title: {
          value: 'ProcessMonitoring.title',
          status: true,
        },
        'x-decorator': 'Container',
        'x-component': 'ProcessMonitoring',
        'x-component-props': defaultProps,
      },
    },
  ],
};

export const defaultBehavior = {
  name: 'ProcessMonitoring',
  extends: ['Field'],
  selector: (node: any) => node.props['x-component'] === 'ProcessMonitoring',
  designerProps: { propsSchema: Schema },
  designerLocales: locale,
};
